part of 'system_windows.dart';

abstract class WindowsBox {
  WindowsBox(
      {this.path = 'assets/landscape.mp4',
      required this.rect,
      this.packageName = 'system_windows'});

  ///  ios 需要的视频地址
  ///  用于修改ios悬浮框尺寸的视频地址
  final String path;

  ///  ios 悬浮框弹出前视频的初始大小
  ///  android 窗口大小
  final Rect rect;

  /// ios 配置视频地址的 packageName
  final String? packageName;

  Map<String, dynamic> toMap() =>
      {'path': path, 'packageName': packageName}..addAll(rect.toLTWH());
}

/// 文字框
class TextBox extends WindowsBox {
  TextBox(
      {this.num = 1,
      this.fontSize = 16,
      super.path,
      required super.rect,
      super.packageName});

  /// 需要添加的 文字数量
  final int num;

  /// 字体大小
  final int fontSize;

  @override
  Map<String, dynamic> toMap() =>
      super.toMap()..addAll({'num': num, 'type': 0, 'fontSize': fontSize});

  /// 更新文字内容
  Future<bool?> updateText(List<String> text) async {
    assert(text.length == num, '列表长度必须等于 $num');
    return await _channel.invokeMethod<bool?>('updateTextBoxText', text);
  }
}

/// 录音框
class RecordBox extends WindowsBox {
  RecordBox(
      {required this.iconPath,
      super.path,
      this.fontSize = 16,
      required super.rect,
      super.packageName});

  final String iconPath;

  /// 字体大小
  final int fontSize;

  @override
  Map<String, dynamic> toMap() => super.toMap()
    ..addAll({'iconPath': iconPath, 'type': 1, 'fontSize': fontSize});

  /// 更新时间
  Future<bool?> updateTime(String time) =>
      _channel.invokeMethod<bool?>('updateRecordBoxTime', time);

  /// 更新录音状态
  Future<bool?> updateState(bool recording) =>
      _channel.invokeMethod<bool?>('updateRecordState', recording);
}

extension ExtensionRect on Rect {
  Map<String, double> toLTWH() =>
      {'left': left, 'top': top, 'width': width, 'height': height};
}
